package com.banmao.Offer.No58Ⅱ;

/**
 *  我的题解，用StringBuilder，效率很低
 *  Carl的题解跟我一样用StringBuilder，毕竟Java里String不可变
 */
public class Solution1 {

    public String reverseLeftWords(String s, int n) {
        StringBuilder sb = new StringBuilder(s);
        reverse(sb, 0, n - 1);
        reverse(sb, n, sb.length() - 1);
        reverse(sb, 0, sb.length() - 1);
        return sb.toString();
    }

    private static void reverse(StringBuilder s, int start, int end) {

        while (start < end) {
            char temp = s.charAt(start);
            s.setCharAt(start, s.charAt(end));
            s.setCharAt(end, temp);
            start++;
            end--;
        }
    }


}
